package team.seekers.catering.food.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import team.seekers.catering.common.enums.DRIsEnum;
import team.seekers.catering.food.entity.dto.add.IngredientAddDTO;
import team.seekers.catering.food.entity.pojo.ContainIngredientListDTO;
import team.seekers.catering.food.entity.dao.Ingredient;
import team.seekers.catering.food.entity.dto.update.IngredientUpdateDTO;
import team.seekers.catering.food.entity.pojo.ContainNutrimentListDO;
import team.seekers.catering.food.entity.pojo.ContainNutrimentListVO;
import team.seekers.catering.food.entity.pojo.IngredientAnalyzeDTO;
import team.seekers.catering.food.entity.vo.info.IngredientInfoVO;
import team.seekers.catering.food.entity.vo.list.IngredientListVO;
import team.seekers.catering.food.mapper.IngredientMapper;
import team.seekers.catering.user.entity.vo.info.EatLogAnalyzeInfoVO;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 食材表 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2022-01-21
 */
@Service
public class IngredientService extends ServiceImpl<IngredientMapper, Ingredient> {

    public Map<String, Object> adminPageOrder(long current, long limit, QueryWrapper<Ingredient> wrapper) {
        Page<Ingredient> page = new Page<>(current,limit);
        page(page,wrapper);
        Long total = page.getTotal();
        if(page.getRecords() == null){
            return null;
        }
        System.out.println("获取的记录是"+page.getRecords());

        List<IngredientListVO> list = new ArrayList<>();
        for (Ingredient record : page.getRecords()) {
            IngredientListVO vo = new IngredientListVO();
            BeanUtils.copyProperties(record,vo);
            list.add(vo);
        }
        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("rows",list);
        return map;
    }

    public void setParamFromList(IngredientAnalyzeDTO analyzeDTO) {
        // 百克换克
        BigDecimal hundred = new BigDecimal("100.0");



        BigDecimal price = new BigDecimal("0.0");       // 总成本
        BigDecimal kalSum = new BigDecimal("0.0");      // 总能量
        BigDecimal amountSum  = new BigDecimal("0.0");  // 总质量


        // 营养成分统计
        BigDecimal proSum = new BigDecimal("0.0");         // 蛋白质的总质量
        BigDecimal fatSum = new BigDecimal("0.0");         // 脂肪的总质量
        BigDecimal choSum = new BigDecimal("0.0");         // 碳水的总质量
        BigDecimal fibtgSum = new BigDecimal("0.0");       // 膳食纤维的总质量
        BigDecimal naSum = new BigDecimal("0.0");       // 蛋白质的总质量
        BigDecimal kSum = new BigDecimal("0.0");        // 脂肪的总质量
        BigDecimal caSum = new BigDecimal("0.0");       // 碳水的总质量
        BigDecimal mgSum = new BigDecimal("0.0");       // 镁的总质量
        BigDecimal pSum = new BigDecimal("0.0");        // 磷的总质量
        BigDecimal feSum = new BigDecimal("0.0");       // 铁的总质量
        BigDecimal znSum = new BigDecimal("0.0");       // 锌的总质量
        BigDecimal cuSum = new BigDecimal("0.0");       // 铜的总质量
        BigDecimal mnSum = new BigDecimal("0.0");       // 锰的总质量
        BigDecimal iodineSum = new BigDecimal("0.0");   // 碘的总质量
        BigDecimal seSum = new BigDecimal("0.0");       // 硒的总质量
        BigDecimal crSum = new BigDecimal("0.0");       // 铬的总质量
        BigDecimal moSum = new BigDecimal("0.0");       // 钼的总质量
        BigDecimal VITASum = new BigDecimal("0.0");     // 的总质量
        BigDecimal VITDSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal TESum = new BigDecimal("0.0");       // 的总质量
        BigDecimal VITKSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal RIBFSum= new BigDecimal("0.0");      // 的总质量
        BigDecimal THIAHCLSum = new BigDecimal("0.0");  // 的总质量
        BigDecimal NIASum = new BigDecimal("0.0");      // 的总质量
        BigDecimal VITB6ASum = new BigDecimal("0.0");   // 的总质量
        BigDecimal VITB12Sum = new BigDecimal("0.0");   // 的总质量
        BigDecimal FOLSum = new BigDecimal("0.0");      // 的总质量
        BigDecimal PANTACSum = new BigDecimal("0.0");   // 的总质量
        BigDecimal BIOTSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal VITCSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal NACL_EQSum = new BigDecimal("0.0");  // 的总质量

        for (ContainIngredientListDTO containIngredientListDTO : analyzeDTO.getIngredientContent()) {
            Ingredient ingredient = getById(containIngredientListDTO.getId());
            BigDecimal amount = new BigDecimal(containIngredientListDTO.getAmount());


            amountSum = amountSum   .add(ingredient.getNcRemain().multiply(amount));
            price = price           .add(ingredient.getNcPrice().multiply(new BigDecimal(containIngredientListDTO.getAmount())));
            kalSum = kalSum         .add(new BigDecimal(ingredient.getNcEnergy()).multiply(amount).divide(hundred, 2, RoundingMode.HALF_UP));


            proSum = proSum         .add(ingredient.getNcPro()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            fatSum = fatSum         .add(ingredient.getNcFat()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            choSum = choSum         .add(ingredient.getNcCho()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            fibtgSum = fibtgSum     .add(ingredient.getNcFibtg()    .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            naSum = naSum           .add(ingredient.getNcNa()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            kSum = kSum             .add(ingredient.getNcK()        .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            caSum = caSum           .add(ingredient.getNcCa()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            mgSum = mgSum           .add(ingredient.getNcMg()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            pSum = pSum             .add(ingredient.getNcP()        .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            feSum = naSum           .add(ingredient.getNcFe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            znSum = znSum           .add(ingredient.getNcZn()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            cuSum = cuSum           .add(ingredient.getNcCu()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            mnSum = mnSum           .add(ingredient.getNcMn()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            iodineSum = iodineSum   .add(ingredient.getNcIodine()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            seSum = seSum           .add(ingredient.getNcSe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            crSum = crSum           .add(ingredient.getNcCr()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            moSum = moSum           .add(ingredient.getNcMo()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));


            VITASum = VITASum       .add(ingredient.getNcVitaRae()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITDSum = VITDSum       .add(ingredient.getNcVitd()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            TESum = TESum           .add(ingredient.getNcTe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            RIBFSum = RIBFSum       .add(ingredient.getNcRibf()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            NIASum = NIASum         .add(ingredient.getNcNia()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            THIAHCLSum = THIAHCLSum .add(ingredient.getNcThiahcl()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITB6ASum = VITB6ASum   .add(ingredient.getNcVitb6a()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITB12Sum = VITB12Sum   .add(ingredient.getNcVitb12()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            FOLSum = FOLSum         .add(ingredient.getNcFol()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            PANTACSum = PANTACSum   .add(ingredient.getNcPantac()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            BIOTSum = BIOTSum       .add(ingredient.getNcBlot()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITCSum = VITCSum       .add(ingredient.getNcVitc()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            NACL_EQSum = NACL_EQSum .add(ingredient.getNcNaclEq()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
        }

        // 总质量（单位g）
        analyzeDTO.setAmount(amountSum.intValue());
        // 总能量（单位kal）
        analyzeDTO.setKal(kalSum.intValue());
        // 总成本价
        analyzeDTO.setPrice(price);

        // 百克含量
        BigDecimal proPerHun =      proSum.multiply(hundred)    .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal fatPerHun =      fatSum.multiply(hundred)    .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal choPerHun =      choSum.multiply(hundred)    .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal fibtgPerHun =    fibtgSum.multiply(hundred)  .divide(amountSum, 4, RoundingMode.HALF_UP);

        BigDecimal naPerHun =       naSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal kPerHun =        kSum.multiply(hundred)      .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal caPerHun =       caSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);



        BigDecimal mgPerHun =       mgSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal pPerHun =        pSum.multiply(hundred)      .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal fePerHun =       feSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal znPerHun =       znSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal cuPerHun =       cuSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal mnPerHun =       mnSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal iodinePerHun =   iodineSum.multiply(hundred) .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal sePerHun =       seSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal crPerHun =       crSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal moPerHun =       moSum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);


        BigDecimal VITAPerHun =     VITASum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal VITDPerHun =     VITDSum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal TEDPerHun =      TESum.multiply(hundred)     .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal VITKPerHun =     VITKSum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal THIAHCLPerHun =  THIAHCLSum.multiply(hundred).divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal RIBFPerHun =     RIBFSum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal NIAPerHun =      NIASum.multiply(hundred)    .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal VITB6APerHun =   VITB6ASum.multiply(hundred) .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal VITB12PerHun =   VITB12Sum.multiply(hundred) .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal FOLPerHun =      FOLSum.multiply(hundred)    .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal PANTACPerHun =   PANTACSum.multiply(hundred) .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal BIOTPerHun =     BIOTSum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal VITCPerHun =     VITCSum.multiply(hundred)   .divide(amountSum, 4, RoundingMode.HALF_UP);
        BigDecimal NACL_EQPerHun =  NACL_EQSum.multiply(hundred).divide(amountSum, 4, RoundingMode.HALF_UP);




        // 能量密度
        BigDecimal kalPerHun = kalSum.divide(amountSum, 2, RoundingMode.HALF_UP).multiply(hundred);
        analyzeDTO.setEd(kalPerHun);

        // 供能比计算
        BigDecimal allEr = proSum.multiply(new BigDecimal("4.0")).add(
                fatSum.multiply(new BigDecimal("9.0")).add(
                        choSum.multiply(new BigDecimal("4.0"))
                )
        );
        BigDecimal proEr = proSum.multiply(new BigDecimal("400")).divide(allEr, 2, RoundingMode.HALF_UP);
        BigDecimal fatEr = fatSum.multiply(new BigDecimal("900")).divide(allEr, 2, RoundingMode.HALF_UP);
        BigDecimal choEr = choSum.multiply(new BigDecimal("400")).divide(allEr, 2, RoundingMode.HALF_UP);
        analyzeDTO.setProEr(proEr.intValue());
        analyzeDTO.setFatEr(fatEr.intValue());
        analyzeDTO.setChoEr(choEr.intValue());

        double kalPow = Math.pow(kalPerHun.doubleValue(), 0.7);
        BigDecimal kalPerHunPow = new BigDecimal(kalPow);

        // 饱腹感指数计算
        BigDecimal satietyIndex = new BigDecimal("41.7").divide(kalPerHunPow, 2, RoundingMode.HALF_UP).add(
                new BigDecimal("0.05").multiply(proPerHun)).add(
                new BigDecimal("0.000617").multiply(fibtgPerHun.pow(3))).subtract(
                new BigDecimal("0.00000725").multiply(fatPerHun.pow(3))).add(
                new BigDecimal("0.617"));

        satietyIndex = satietyIndex.max(new BigDecimal("0.5")).min(new BigDecimal("5.0"));
        analyzeDTO.setSatietyIndex(satietyIndex);

        // 营养素参考值计算（能量、蛋白质、脂肪、碳水化合物、膳食纤维、钠、钾、钙、VC）
        ArrayList<ContainNutrimentListDO> foodContentDTOS = new ArrayList<>();
        // 能量
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.KAL.getValue(),
                        kalPerHun.doubleValue(),
                        kalPerHun.divide(BigDecimal.valueOf(DRIsEnum.KAL.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 蛋白质
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.PRO.getValue(),proPerHun.doubleValue(),proPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.PRO.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 脂肪
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.FAT.getValue(),fatPerHun.doubleValue(),fatPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FAT.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 碳水化合物
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.CHO.getValue(),choPerHun.doubleValue(),choPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CHO.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 膳食纤维
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.FIBTG.getValue(),fibtgPerHun.doubleValue(),fibtgPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FIBTG.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 钠
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.NA.getValue(),naPerHun.doubleValue(),naPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NA.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 钾
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.K.getValue(),kPerHun.doubleValue(),kPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.K.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 钙
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.CA.getValue(),caPerHun.doubleValue(),caPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CA.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 镁
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.MG.getValue(),mgPerHun.doubleValue(),mgPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MG.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 磷
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.P.getValue(),pPerHun.doubleValue(),pPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.P.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 铁
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.FE.getValue(),fePerHun.doubleValue(),fePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FE.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 锌
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.ZN.getValue(),znPerHun.doubleValue(),znPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.ZN.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 铜
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.CU.getValue(),cuPerHun.doubleValue(),cuPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CU.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 猛
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.MN.getValue(),mnPerHun.doubleValue(),mnPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MN.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 碘
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.IODINE.getValue(),iodinePerHun.doubleValue(),iodinePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.IODINE.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 硒
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.SE.getValue(),sePerHun.doubleValue(),sePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.SE.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 铬
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.CR.getValue(),crPerHun.doubleValue(),crPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CR.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 钼
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.MO.getValue(),moPerHun.doubleValue(),moPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MO.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 维生素A(视黄醇活性当量)
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITA_RAE.getValue(),VITAPerHun.doubleValue(),VITAPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITA_RAE.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 维生素D
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITD.getValue(),VITDPerHun.doubleValue(),VITDPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITD.getAmount()), 4, RoundingMode.HALF_UP).toString()));

        // 维生素E(α-生育酚当量)
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.TE_D.getValue(),TEDPerHun.doubleValue(),TEDPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.TE_D.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 维生素K
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITK.getValue(),VITKPerHun.doubleValue(),VITKPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITK.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 维生素B1
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.THIAHCL.getValue(),THIAHCLPerHun.doubleValue(),THIAHCLPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.THIAHCL.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 维生素B2
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.RIBF.getValue(),RIBFPerHun.doubleValue(),RIBFPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.RIBF.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 烟酸
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.NIA.getValue(),NIAPerHun.doubleValue(),NIAPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NIA.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 维生素B6
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITB6A.getValue(),VITB6APerHun.doubleValue(),VITB6APerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITB6A.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 维生素B12
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITB12.getValue(),VITB12PerHun.doubleValue(),VITB12PerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITB12.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 叶酸
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.FOL.getValue(),FOLPerHun.doubleValue(),FOLPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FOL.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 泛酸
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.PANTAC.getValue(),PANTACPerHun.doubleValue(),PANTACPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.PANTAC.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 生物素
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.BIOT.getValue(),BIOTPerHun.doubleValue(),BIOTPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.BIOT.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // VC
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.VITC.getValue(),VITCPerHun.doubleValue(),VITCPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITC.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        // 食盐当量
        foodContentDTOS.add(
                new ContainNutrimentListDO(DRIsEnum.NACL_EQ.getValue(),NACL_EQPerHun.doubleValue(),NACL_EQPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NACL_EQ.getAmount()), 4, RoundingMode.HALF_UP).toString()));
        analyzeDTO.setNrv(foodContentDTOS);

        // 计算营养饱和度
        BigDecimal nfs = new BigDecimal("0.0");
        for (int i = 1;i<=30;i++){
            if(i == 2 || i ==  3 || i == 5){
                continue;
            }
            BigDecimal temp = new BigDecimal("1000").multiply(new BigDecimal(foodContentDTOS.get(i).getNutrimentContent()))
                                                        .divide(kalPerHun, 4, RoundingMode.HALF_UP);
            nfs = nfs.add(new BigDecimal("1").min(temp));
        }
        analyzeDTO.setNfs(nfs.multiply(new BigDecimal("100.0")).divide(new BigDecimal("27.0"),4, RoundingMode.HALF_UP));
    }

    public IngredientInfoVO get(String id) {
        Ingredient ingredient = getById(id);
        IngredientInfoVO ingredientInfoVO = new IngredientInfoVO();
        BeanUtils.copyProperties(ingredient,ingredientInfoVO);
        return ingredientInfoVO;
    }

    public Long update(IngredientUpdateDTO ingredientUpdateDTO) {
        Ingredient ingredient = new Ingredient();
        BeanUtils.copyProperties(ingredientUpdateDTO,ingredient);
        updateById(ingredient);
        return ingredient.getNcId();
    }

    public Long create(IngredientAddDTO addPA) {
        Ingredient ingredient = new Ingredient();
        BeanUtils.copyProperties(addPA,ingredient);
        Integer ncType = addPA.getNcType();
        QueryWrapper<Ingredient> wrapper = new QueryWrapper<>();
        wrapper.select("nc_id").eq("nc_type",ncType);
        List<Object> collect = baseMapper.selectObjs(wrapper);
        List<BigInteger> longs = (List<BigInteger>)(List) collect;
        BigInteger max = Collections.max(longs);
        ingredient.setNcId(max.longValue()+1);
        save(ingredient);
        return ingredient.getNcId();
    }

    public void setVOFromList(EatLogAnalyzeInfoVO analyzeInfoVO) {
        // 百克换克
        BigDecimal hundred = new BigDecimal("100.0");



        BigDecimal price = new BigDecimal("0.0");       // 总成本
        BigDecimal kalSum = new BigDecimal("0.0");      // 总能量
        BigDecimal amountSum  = new BigDecimal("0.0");  // 总质量


        // 营养成分统计
        BigDecimal proSum = new BigDecimal("0.0");         // 蛋白质的总质量
        BigDecimal fatSum = new BigDecimal("0.0");         // 脂肪的总质量
        BigDecimal choSum = new BigDecimal("0.0");         // 碳水的总质量
        BigDecimal fibtgSum = new BigDecimal("0.0");       // 膳食纤维的总质量
        BigDecimal naSum = new BigDecimal("0.0");       // 蛋白质的总质量
        BigDecimal kSum = new BigDecimal("0.0");        // 脂肪的总质量
        BigDecimal caSum = new BigDecimal("0.0");       // 碳水的总质量
        BigDecimal mgSum = new BigDecimal("0.0");       // 镁的总质量
        BigDecimal pSum = new BigDecimal("0.0");        // 磷的总质量
        BigDecimal feSum = new BigDecimal("0.0");       // 铁的总质量
        BigDecimal znSum = new BigDecimal("0.0");       // 锌的总质量
        BigDecimal cuSum = new BigDecimal("0.0");       // 铜的总质量
        BigDecimal mnSum = new BigDecimal("0.0");       // 锰的总质量
        BigDecimal iodineSum = new BigDecimal("0.0");   // 碘的总质量
        BigDecimal seSum = new BigDecimal("0.0");       // 硒的总质量
        BigDecimal crSum = new BigDecimal("0.0");       // 铬的总质量
        BigDecimal moSum = new BigDecimal("0.0");       // 钼的总质量
        BigDecimal VITASum = new BigDecimal("0.0");     // 的总质量
        BigDecimal VITDSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal TESum = new BigDecimal("0.0");       // 的总质量
        BigDecimal VITKSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal RIBFSum= new BigDecimal("0.0");      // 的总质量
        BigDecimal THIAHCLSum = new BigDecimal("0.0");  // 的总质量
        BigDecimal NIASum = new BigDecimal("0.0");      // 的总质量
        BigDecimal VITB6ASum = new BigDecimal("0.0");   // 的总质量
        BigDecimal VITB12Sum = new BigDecimal("0.0");   // 的总质量
        BigDecimal FOLSum = new BigDecimal("0.0");      // 的总质量
        BigDecimal PANTACSum = new BigDecimal("0.0");   // 的总质量
        BigDecimal BIOTSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal VITCSum = new BigDecimal("0.0");     // 的总质量
        BigDecimal NACL_EQSum = new BigDecimal("0.0");  // 的总质量

        for (ContainIngredientListDTO containIngredientListDTO : analyzeInfoVO.getIngredientContent()) {
            Ingredient ingredient = getById(containIngredientListDTO.getId());
            BigDecimal amount = new BigDecimal(containIngredientListDTO.getAmount());


            amountSum = amountSum   .add(ingredient.getNcRemain().multiply(amount));
            price = price           .add(ingredient.getNcPrice().multiply(new BigDecimal(containIngredientListDTO.getAmount())));
            kalSum = kalSum         .add(new BigDecimal(ingredient.getNcEnergy()).multiply(amount).divide(hundred, 2, RoundingMode.HALF_UP));


            proSum = proSum         .add(ingredient.getNcPro()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            fatSum = fatSum         .add(ingredient.getNcFat()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            choSum = choSum         .add(ingredient.getNcCho()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            fibtgSum = fibtgSum     .add(ingredient.getNcFibtg()    .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            naSum = naSum           .add(ingredient.getNcNa()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            kSum = kSum             .add(ingredient.getNcK()        .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            caSum = caSum           .add(ingredient.getNcCa()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            mgSum = mgSum           .add(ingredient.getNcMg()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            pSum = pSum             .add(ingredient.getNcP()        .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            feSum = naSum           .add(ingredient.getNcFe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            znSum = znSum           .add(ingredient.getNcZn()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            cuSum = cuSum           .add(ingredient.getNcCu()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            mnSum = mnSum           .add(ingredient.getNcMn()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            iodineSum = iodineSum   .add(ingredient.getNcIodine()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            seSum = seSum           .add(ingredient.getNcSe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            crSum = crSum           .add(ingredient.getNcCr()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            moSum = moSum           .add(ingredient.getNcMo()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));


            VITASum = VITASum       .add(ingredient.getNcVitaRae()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITDSum = VITDSum       .add(ingredient.getNcVitd()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            TESum = TESum           .add(ingredient.getNcTe()       .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            RIBFSum = RIBFSum       .add(ingredient.getNcRibf()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            NIASum = NIASum         .add(ingredient.getNcNia()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            THIAHCLSum = THIAHCLSum .add(ingredient.getNcThiahcl()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITB6ASum = VITB6ASum   .add(ingredient.getNcVitb6a()  .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITB12Sum = VITB12Sum   .add(ingredient.getNcVitb12()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            FOLSum = FOLSum         .add(ingredient.getNcFol()      .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            PANTACSum = PANTACSum   .add(ingredient.getNcPantac()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            BIOTSum = BIOTSum       .add(ingredient.getNcBlot()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            VITCSum = VITCSum       .add(ingredient.getNcVitc()     .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
            NACL_EQSum = NACL_EQSum .add(ingredient.getNcNaclEq()   .multiply(amount).divide(hundred, 4, RoundingMode.HALF_UP));
        }

        // 总质量（单位g）
        analyzeInfoVO.setAmount(amountSum.intValue());
        // 总能量（单位kal）
        analyzeInfoVO.setKal(kalSum.intValue());
        // 总成本价
        analyzeInfoVO.setPrice(price);

        // 百克含量
        BigDecimal proPerHun =      proSum.multiply(hundred)    .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal fatPerHun =      fatSum.multiply(hundred)    .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal choPerHun =      choSum.multiply(hundred)    .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal fibtgPerHun =    fibtgSum.multiply(hundred)  .divide(amountSum, 1, RoundingMode.HALF_UP);

        BigDecimal naPerHun =       naSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal kPerHun =        kSum.multiply(hundred)      .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal caPerHun =       caSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);



        BigDecimal mgPerHun =       mgSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal pPerHun =        pSum.multiply(hundred)      .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal fePerHun =       feSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal znPerHun =       znSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal cuPerHun =       cuSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal mnPerHun =       mnSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal iodinePerHun =   iodineSum.multiply(hundred) .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal sePerHun =       seSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal crPerHun =       crSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal moPerHun =       moSum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);


        BigDecimal VITAPerHun =     VITASum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal VITDPerHun =     VITDSum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal TEDPerHun =      TESum.multiply(hundred)     .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal VITKPerHun =     VITKSum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal THIAHCLPerHun =  THIAHCLSum.multiply(hundred).divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal RIBFPerHun =     RIBFSum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal NIAPerHun =      NIASum.multiply(hundred)    .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal VITB6APerHun =   VITB6ASum.multiply(hundred) .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal VITB12PerHun =   VITB12Sum.multiply(hundred) .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal FOLPerHun =      FOLSum.multiply(hundred)    .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal PANTACPerHun =   PANTACSum.multiply(hundred) .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal BIOTPerHun =     BIOTSum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal VITCPerHun =     VITCSum.multiply(hundred)   .divide(amountSum, 1, RoundingMode.HALF_UP);
        BigDecimal NACL_EQPerHun =  NACL_EQSum.multiply(hundred).divide(amountSum, 1, RoundingMode.HALF_UP);




        // 能量密度
        BigDecimal kalPerHun = kalSum.divide(amountSum, 1, RoundingMode.HALF_UP).multiply(hundred);
        analyzeInfoVO.setEd(kalPerHun);

        // 供能比计算
        BigDecimal allEr = proSum.multiply(new BigDecimal("4.0")).add(
                fatSum.multiply(new BigDecimal("9.0")).add(
                        choSum.multiply(new BigDecimal("4.0"))
                )
        );
        BigDecimal proEr = proSum.multiply(new BigDecimal("400")).divide(allEr, 2, RoundingMode.HALF_UP);
        BigDecimal fatEr = fatSum.multiply(new BigDecimal("900")).divide(allEr, 2, RoundingMode.HALF_UP);
        BigDecimal choEr = choSum.multiply(new BigDecimal("400")).divide(allEr, 2, RoundingMode.HALF_UP);
        analyzeInfoVO.setProEr(proEr.intValue());
        analyzeInfoVO.setFatEr(fatEr.intValue());
        analyzeInfoVO.setChoEr(choEr.intValue());

        double kalPow = Math.pow(kalPerHun.doubleValue(), 0.7);
        BigDecimal kalPerHunPow = new BigDecimal(kalPow);

        // 饱腹感指数计算
        BigDecimal satietyIndex = new BigDecimal("41.7").divide(kalPerHunPow, 2, RoundingMode.HALF_UP).add(
                new BigDecimal("0.05").multiply(proPerHun)).add(
                new BigDecimal("0.000617").multiply(fibtgPerHun.pow(3))).subtract(
                new BigDecimal("0.00000725").multiply(fatPerHun.pow(3))).add(
                new BigDecimal("0.617"));

        satietyIndex = satietyIndex.max(new BigDecimal("0.5")).min(new BigDecimal("5.0"));
        analyzeInfoVO.setSatietyIndex(satietyIndex);

        // 营养素参考值计算（能量、蛋白质、脂肪、碳水化合物、膳食纤维、钠、钾、钙、VC）
        ArrayList<ContainNutrimentListVO> foodContentDTOS = new ArrayList<>();
        // 能量
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.KAL.getName(),
                        kalPerHun.toString(),
                        kalPerHun.divide(BigDecimal.valueOf(DRIsEnum.KAL.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 蛋白质
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.PRO.getName(),proPerHun.toString(),proPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.PRO.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 脂肪
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.FAT.getName(),fatPerHun.toString(),fatPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FAT.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 碳水化合物
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.CHO.getName(),choPerHun.toString(),choPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CHO.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 膳食纤维
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.FIBTG.getName(),fibtgPerHun.toString(),fibtgPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FIBTG.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 钠
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.NA.getName(),naPerHun.toString(),naPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NA.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 钾
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.K.getName(),kPerHun.toString(),kPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.K.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 钙
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.CA.getName(),caPerHun.toString(),caPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CA.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 镁
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.MG.getName(),mgPerHun.toString(),mgPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MG.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 磷
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.P.getName(),pPerHun.toString(),pPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.P.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 铁
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.FE.getName(),fePerHun.toString(),fePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FE.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 锌
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.ZN.getName(),znPerHun.toString(),znPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.ZN.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 铜
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.CU.getName(),cuPerHun.toString(),cuPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CU.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 猛
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.MN.getName(),mnPerHun.toString(),mnPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MN.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 碘
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.IODINE.getName(),iodinePerHun.toString(),iodinePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.IODINE.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 硒
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.SE.getName(),sePerHun.toString(),sePerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.SE.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 铬
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.CR.getName(),crPerHun.toString(),crPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.CR.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 钼
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.MO.getName(),moPerHun.toString(),moPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.MO.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 维生素A(视黄醇活性当量)
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITA_RAE.getName(),VITAPerHun.toString(),VITAPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITA_RAE.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 维生素D
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITD.getName(),VITDPerHun.toString(),VITDPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITD.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));

        // 维生素E(α-生育酚当量)
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.TE_D.getName(),TEDPerHun.toString(),TEDPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.TE_D.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 维生素K
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITK.getName(),VITKPerHun.toString(),VITKPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITK.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 维生素B1
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.THIAHCL.getName(),THIAHCLPerHun.toString(),THIAHCLPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.THIAHCL.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 维生素B2
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.RIBF.getName(),RIBFPerHun.toString(),RIBFPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.RIBF.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 烟酸
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.NIA.getName(),NIAPerHun.toString(),NIAPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NIA.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 维生素B6
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITB6A.getName(),VITB6APerHun.toString(),VITB6APerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITB6A.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 维生素B12
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITB12.getName(),VITB12PerHun.toString(),VITB12PerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITB12.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 叶酸
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.FOL.getName(),FOLPerHun.toString(),FOLPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.FOL.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 泛酸
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.PANTAC.getName(),PANTACPerHun.toString(),PANTACPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.PANTAC.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 生物素
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.BIOT.getName(),BIOTPerHun.toString(),BIOTPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.BIOT.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // VC
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.VITC.getName(),VITCPerHun.toString(),VITCPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.VITC.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        // 食盐当量
        foodContentDTOS.add(
                new ContainNutrimentListVO(DRIsEnum.NACL_EQ.getName(),NACL_EQPerHun.toString(),NACL_EQPerHun.divide(
                        BigDecimal.valueOf(DRIsEnum.NACL_EQ.getAmount()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toString()));
        analyzeInfoVO.setNrvVO(foodContentDTOS);

        // 计算营养饱和度
        BigDecimal nfs = new BigDecimal("0.0");
        for (int i = 1;i<=30;i++){
            if(i == 2 || i ==  3 || i == 5){
                continue;
            }
            BigDecimal temp = new BigDecimal("1000").multiply(new BigDecimal(foodContentDTOS.get(i).getNutrimentContent()))
                    .divide(kalPerHun, 4, RoundingMode.HALF_UP);
            nfs = nfs.add(new BigDecimal("1").min(temp));
        }
        analyzeInfoVO.setNfs(nfs.multiply(new BigDecimal("100.0")).divide(new BigDecimal("27.0"),4, RoundingMode.HALF_UP));
    }
}
